 <?php
/*   Description  of this file
*    Author king-of-war
*    Last Modified 2009-4-8
*    This class designed  for the news operation
*/




class fun_common{

	private $root_path;

	function __construct($url){


		/*
		 * load connection class
		 */
		$this->set_root_path($url);


	}

 /*
  * defin the function for create editor
  *
  *create the editor
  * $name nean names   $w mean width  $h means heidth  $toobar mean toobarset  $value mean value
  *
  */


	function create_editor($name,$h,$w,$toobar,$comments){

$root_path=$this->get_root_path();
include_once $root_path.'includes/editor/fckeditor.php';
$editor=new FCKeditor($name) ;
$editor->BasePath = $root_path.'/includes/editor/' ;
$editor->Config['EnterMode'] = 'br';
$editor->DefaultLanguage = "zh-cn";
$editor->Width="600";
$editor->Height="400";
$editor->ToolbarSet="liujie";
$editor->Value = $comments;
$editor->Create();
}

/*
*  define  page function
*  $page_start $page_size $admin
* return the limit sql;   total items total_pages
*/
function page($page,$page_size,$max){
   $pages=array();

 $total=ceil($max/$page_size);

   if($page>$total){
   	echo '<h1><font color="red">over pages range</font></h1>';
   	}else{
    $page_start=($page-1)*$page_size;
$pages['start']=$page_start;
$pages['total']=$total;
}
/*
 * check the range
 */
if($page<2){
	$pages['pre']=1;
}else{
$pages['pre']=$page-1;
}
if($page<$pages['total']){
$pages['next']=$page+1;

}else{
	$pages['next']=$pages['total'];
}
/*
 * define current page
 */
$pages['cur']=$page;
/*
 * end
 */


return $pages;
}

    /*
    *   get total numbers of $part
    *   $part: table name
    *    $admin: select's condition
    */
    function getAll($part,$admin){
  	$url=$this->get_root_path();
    include_once $url.'includes/conn.php';
    $conn=new conn();
    if($admin){
    	$condition='';
    }else{
    	$condition="where verify='1'";
    	}
    $sql=sprintf("select id from  %s  %s",$part,$condition);


  	$conn->set_sql($sql);

  	$line=$conn->get_line();

  	return $line;
    	}

    /*
    *   get total numbers of $part
    *   $part: table name
    *    $admin: select's condition
    */
    function get_part($part,$condition){
  	$url=$this->get_root_path();
    include_once $url.'includes/conn.php';

    $conn=new conn();

    $sql=sprintf("select * from  %s  %s",$part,$condition);


  	$conn->set_sql($sql);

  	$line=$conn->get_line();

  	return $line;
    	}




	/*
	 * functions for use above
	 */
	function set_root_path($url){
		$this->root_path=$url;
	}
	function get_root_path(){
		return	$this->root_path;
	}

}
?>